﻿/**

 layui官网

*/

layui.define(['layer','form', 'element', 'util'], function (exports) {
    var $ = layui.jquery
    , layer = layui.layer
    , form = layui.form()
    , util = layui.util;

   
    //固定Bar
    util.fixbar({
        bar1: true
      , click: function (type) {
          if (type === 'bar1') {
              location.href = 'http://fly.layui.com/';
          }
      }
    });

    //窗口scroll
    ; !function () {
        var main = $('.site-tree').parent(), scroll = function () {
            var stop = $(window).scrollTop();
            if ($(window).width() <= 750) return;
            var bottom = $('.footer').offset().top - $(window).height();
            if (stop > 61 && stop < bottom) {
                if (!main.hasClass('site-fix')) {
                    main.addClass('site-fix');
                }
                if (main.hasClass('site-fix-footer')) {
                    main.removeClass('site-fix-footer');
                }
            } else if (stop >= bottom) {
                if (!main.hasClass('site-fix-footer')) {
                    main.addClass('site-fix site-fix-footer');
                }
            } else {
                if (main.hasClass('site-fix')) {
                    main.removeClass('site-fix').removeClass('site-fix-footer');
                }
            }
            stop = null;
        };
        scroll();
        $(window).on('scroll', scroll);
    }();

    

    //目录
    var siteDir = $('.site-dir');
    if (siteDir[0] && $(window).width() > 750) {
        layer.open({
            type: 1
          , content: siteDir
          , skin: 'layui-layer-dir'
          , area: 'auto'
          , title: '目录'
          , offset: 'rc'
          , shade: false
          , success: function (layero, index) {
              layer.style(index, {
                  marginLeft: -15
              })
          }
        });
        siteDir.find('li').on('click', function () {
            var othis = $(this);
            othis.find('a').addClass('layui-this');
            othis.siblings().find('a').removeClass('layui-this');
        });
    }



 

    var iframe = $('#LAY_demo').prop('contentWindow');
    $('#LAY_demo_run').on('click', function () {
        iframe.layui.jquery('body').html($('#LAY_editor').val());
        if (iframe.layui.form) {
            iframe.layui.form().render();
        }
    });


    //手机设备的简单适配
    var treeMobile = $('.site-tree-mobile')
    , shadeMobile = $('.site-mobile-shade')

    treeMobile.on('click', function () {
        $('body').addClass('site-mobile');
    });

    shadeMobile.on('click', function () {
        $('body').removeClass('site-mobile');
    });

    exports('global', {});
});